package org.example.dao.impl;

import org.example.dao.UserDao;
import org.example.entity.User;

import java.util.List;

/**
 * 用户的数据访问层类，它是UserDao接口的实现类
 */
public class UserDaoImpl implements UserDao {
    // 在数据访问层，对用户就是查询的动作
    public User getUserByUserName(String userName) {
        String sql = "SELECT * FROM `user` WHERE user_name = ?";
        List<User> users = DBUtil.executeQuery(User::map,sql,userName);
        if(users.size() > 0) {
            return users.get(0);
        }
        return null;
    }
}
